/*
GET
Ajax.Request('get', url, '', update_city_select,"responseXML");

GET
Ajax.Request('post', url, 'var1=value1&var2=value2', update_city_select,"responseXML");

form 
Post.OnResponse=function(){};
Post.send(form);

*/

/* responseType:
responseXML
responseText
*/

var oNeoAjax = new Object();
		oNeoAjax.isUpdating = true;

		oNeoAjax.Request = function(method, url, query, callback,responseType )
		{
		if (!responseType) responseType='responseXML';
			this.isUpdating = true;
			this.responseType=responseType;
			this.callbackMethod = callback;
			this.xmlhttp = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
			this.xmlhttp.onreadystatechange = function() { oNeoAjax.checkReadyState(); };

			if(method.toLowerCase() == 'get') url = url+"?"+query;
			this.xmlhttp.open(method, url, true);
			this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			this.xmlhttp.send(query);
		}

		oNeoAjax.checkReadyState = function()
		{
			switch(this.xmlhttp.readyState)
			{
				case 1: break;
				case 2: break;
				case 3: break;
				case 4:
					this.isUpdating = false;
					switch (this.responseType){
					case "responseText":
					this.callbackMethod(this.xmlhttp.responseText);
					break;
					case "responseXML":
					default:
					this.callbackMethod(this.xmlhttp.responseXML);
				
					}
					
			}
		}
	


var oNeoPost = new Object();
oNeoPost.Send = function(form,callback,responseType)
{
		if (!responseType)  responseType='responseXML';
		if (!callback)  callback=oNeoPost.OnResponse;


	var query = oNeoPost.buildQuery(form);
	oNeoAjax.Request(form.method, form.action, query, callback,responseType);
}

oNeoPost.OnResponse = function(xml)
{
	var results = document.createElement('div');
	document.getElementsByTagName('body')[0].appendChild(results)
	results.innerHTML = xml.firstChild.nodeValue;
}

oNeoPost.buildQuery = function(form)
{
	  var submitContent = '';
    var formElem;
    var lastElemName = '';

    for(i = 0; i < form.elements.length; i++ ) {
        formElem = form.elements[i];
        switch( formElem.type ) {
            // Text fields, hidden form elements
            case 'text':
            case 'hidden':
            case 'password':
            case 'textarea':
            case 'select-one':
                submitContent += formElem.name + '=' + escape(formElem.value) + '&';
                break;
           
            // Radio buttons
            case 'radio':
                if( formElem.checked ) submitContent += formElem.name + '=' + escape(formElem.value) + '&';
                break;
           
            // Checkboxes
            case 'checkbox':
                if( formElem.checked ) {
                    // Continuing multiple, same-name checkboxes
                    if( formElem.name == lastElemName ) {
                        // Strip off end ampersand if there is one
                        if( submitContent.lastIndexOf('&') == submitContent.length-1 ) {
                            submitContent = submitContent.substr(0, submitContent.length - 1);
                        }
                        submitContent += '&' + formElem.name + '=' + escape(formElem.value);
                    } else {
                        submitContent += formElem.name + '=' + escape(formElem.value);
                    }
                    submitContent += '&';
                    lastElemName = formElem.name;
                }
                break;
        }
    }
   
    // Remove trailing separator
    submitContent = submitContent.substr(0, submitContent.length - 1);
   
    return submitContent;
}
